var imgSrc=["../images/index_slide1.jpg","../images/index_slide2.jpg","../images/index_slide3.jpg","../images/index_slide4.jpg",           "../images/index_slide5.jpg","../images/index_slide6.jpg"];//存储轮播对象图片资源
var index=0;//记录轮播对象移动下标
var objsetInterval;//定时轮播对象


window.onload=function(){
	//为话费，彩票模块设置默认激活状态
	var huafeiLi=document.getElementById("huafei").getElementsByTagName('li');
	var huafeiImg=document.getElementById("huafei").getElementsByTagName('img');
	for(var i=0;i<huafeiLi.length;i++){
		if(huafeiLi[i].className=='active'){
			huafeiImg[i].style.display='block';			
			}
		}
	//为疯狂抢购，热卖商品模块设置默认激活状态	
	var qianggouLi=document.getElementById("qianggou").getElementsByTagName('li');
	var qianggouShow=document.getElementById("qianggou").getElementsByClassName('qianggousub');
	
	for(var i=0;i<qianggouLi.length;i++){
		if(qianggouLi[i].className=='active'){
			qianggouShow[i].style.display='block';			
			}
	}
	//为推荐商品，电脑整机模块设置默认激活状态
	var shangpinLi=document.getElementById("shangpin").getElementsByTagName('li');
	var shangpinShow=document.getElementById("shangpin").getElementsByClassName('shangpinsub');
	
	for(var i=0;i<shangpinLi.length;i++){
		if(shangpinLi[i].className=='active'){
			shangpinShow[i].style.display='block';			
			}
	}
		
						
	//轮播	
	var targetImg=document.getElementById("targetImg");
    var btns=document.getElementById("btns").getElementsByTagName('li');
     //设置定时轮播
	objsetInterval=setInterval(lunboSetInterval,1500);
	
	
	//定时轮播
	function lunboSetInterval(){
	if(index>imgSrc.length-1){
		index=0;
		}
	targetImg.src=imgSrc[index];
	for(var i=0;i<btns.length;i++){
		btns[i].style.background='#999999';
	}	
	btns[index].style.background='red';
	index++;
	}	
	
	//为轮播按钮绑定onmouseover与onmouseout事件
	for(var i=0;i<btns.length;i++){
		btns[i].id=i;
		btns[i].onmouseover=function(){
			
			clearInterval(objsetInterval);
			targetImg.src=imgSrc[this.id];
			
			for(var i=0;i<btns.length;i++){
				btns[i].style.background='#999999';
				}			
			this.style.background='red';
			}
			btns[i].onmouseout=function(){
				index=this.id;
				objsetInterval=setInterval(lunboSetInterval,1500);			
			}	
	}
}



//选项卡
function change(n,m){
	//话费，彩票模块
	if(n==0){
		var huafeiLi=document.getElementById("huafei").getElementsByTagName('li');
		var huafeiImg=document.getElementById("huafei").getElementsByTagName('img');
		
		for(var i=0;i<huafeiLi.length;i++){
			huafeiLi[i].className=i==m?'active':'';
			huafeiImg[i].style.display=i==m?'block':'none';
			}	
	}
	//疯狂抢购，热卖商品模块
	else if(n==1){
		var qianggouLi=document.getElementById("qianggou").getElementsByTagName('li');
		var qianggouShow=document.getElementById("qianggou").getElementsByClassName('qianggousub');
		
		for(var i=0;i<qianggouLi.length;i++){
			qianggouLi[i].className=i==m?'active':'';
			qianggouShow[i].style.display=i==m?'block':'none';
			}	
	}
	//推荐商品，电脑整机模块
	else{
		
		var shangpinLi=document.getElementById("shangpin").getElementsByTagName('li');
		var shangpinShow=document.getElementById("shangpin").getElementsByClassName('shangpinsub');
		
		for(var i=0;i<shangpinLi.length;i++){
			shangpinLi[i].className=i==m?'active':'';
			shangpinShow[i].style.display=i==m?'block':'none';
			}	
	}
}
